import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ui_demo/page/main/main_page.dart';
import 'package:flutter_ui_demo/res/colors.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    final botToastBuilder = BotToastInit();
    return MaterialApp(
      title: 'Flutter UI Demo',
      builder: (context, child) {
        child = _buildMediaQuery(context, child);
        child = botToastBuilder(context, child);
        return child;
      },
      //registered route observer
      navigatorObservers: [BotToastNavigatorObserver()],
      theme: ThemeData(
        primaryColor: Colours.app_primaryColor,
      ),
      home: MainPage(),
    );
  }

  /// 过渡建设者
  /// 主界面构建前,整体添加的构建步骤;
  /// 该处用来处理文本字体大小不随系统字体大小改变;
  Widget _buildMediaQuery(BuildContext context, Widget? child) {
    // 或者 MediaQueryData.fromWindow(WidgetsBinding.instance.window).copyWith(textScaleFactor: 1.0),
    // 保证文字大小不受手机系统设置影响 https://www.kikt.top/posts/flutter/layout/dynamic-text/
    return MediaQuery(
      data: MediaQuery.of(context).copyWith(
        textScaleFactor: 1.0,
      ),
      child: child ?? Container(),
    );
  }
}
